package com.kaibes.admin.log;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.kaibes.module.log.ApiLogService;
import com.kaibes.web.admin.AdminMenu;
import com.kaibes.web.admin.AdminMenuRes;
import com.kaibes.web.admin.IconBox;

@Configuration
public class ApiLogInit {
    
    private final static String KEY = "log";
    @Autowired
    private ApiLogService apiLogService;

    @Bean
    public AdminMenu logMenu() {
        AdminMenu menu = new AdminMenu();
        menu.setKey(KEY);
        menu.setName("日志模块");
        menu.setIcon("fas fa-file");
        menu.setHref("");
        menu.setSort(3);
        menu.setParentKey(AdminMenuRes.MENU_BASE);
        return menu;
    }
    
    @Bean
    public AdminMenu logApiMenu() {
        AdminMenu menu = new AdminMenu();
        menu.setKey("log-api");
        menu.setName("API日志");
        menu.setIcon("fas fa-file");
        menu.setHref("/admin/log/api");
        menu.setSort(1);
        menu.setParentKey(KEY);
        return menu;
    }
    
    //================
    @Bean
    public IconBox logBox() {
        IconBox iconBox = new IconBox() {

            @Override
            public void update() {
                setCount(apiLogService.count());
            }
        };
        iconBox.setSort(5);
        iconBox.setName("接口日志");
        iconBox.setClassAppend("bg-danger");
        iconBox.setIcon("ion-alert");
        iconBox.setHref("/admin/log/api");
        return iconBox;
    }
}
